import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:shared_preferences/shared_preferences.dart';

bool turn_on = true;
bool mic_on = false;

int rgbIndex = 0;
String ledNum = '200'; // 存储输入的值

String rgbIndexKey = 'rgbIndexKey';
String ledNumKey = 'ledNumKey';

///主题背景颜色
const Color Color_theme = Color(0xFF56B6F6);
const Color Color_select_btn = Color(0xFF56B6F6);

///键盘色效果
const Color Color_left = Color(0xFF6BCFFB);
const Color Color_right = Color(0xFF2D6EEC);

///子视图背景颜色
const Color Color_bg_view = Color(0xFF1E1E1E);
const Color Color_line_view = Color(0xFF4C4C4E);
const Color Color_alert_view = Color(0xFF252934);

const Color Color_btn_hight = Color(0xFFD32C26);
const LinearGradient localGradient = LinearGradient(
  begin: Alignment.topLeft, // 渐变的开始位置，左边
  end: Alignment.bottomRight, // 渐变的结束位置，右边
  colors: [
    Color_left, // 起始颜色
    Color_right, // 结束颜色
  ],
);

// 保存字符串
Future<void> saveString(String key, String value) async {
  final prefs = await SharedPreferences.getInstance();
  await prefs.setString(key, value);
}

// 获取字符串
Future<String?> getString(String key) async {
  final prefs = await SharedPreferences.getInstance();
  return prefs.getString(key);
}

class GlobalConfig {
  static double scaleH = 0.0;
}

class assets {
  static const String _basePath = 'assets/images/';

  static String getImagePath(String imageName) {
    return '$_basePath$imageName.png';
  }

  // 定义具体的图片资源
  static const String add = '${_basePath}add.png';
  static const String add2 = '${_basePath}add2.png';
  static const String sub2 = '${_basePath}sub2.png';
  static const String back1 = '${_basePath}back1.png';
  static const String back2 = '${_basePath}back2.png';
  static const String bg_color = '${_basePath}bg_color.png';
  static const String bg_color_top = '${_basePath}bg_color_top.png';
  static const String bg_color_bottom = '${_basePath}bg_color_bottom.png';
  static const String bg_search = '${_basePath}bg_search.png';
  static const String bright1 = '${_basePath}bright1.png';
  static const String bright2 = '${_basePath}bright2.png';
  static const String connect = '${_basePath}connect.png';
  static const String disconnect = '${_basePath}disconnect.png';
  static const String DS18 = '${_basePath}DS18.png';
  static const String mic = '${_basePath}mic.png';
  static const String refresh = '${_basePath}refresh.png';
  static const String settings = '${_basePath}settings.png';
  static const String turn_off = '${_basePath}turn_off.png';
  static const String delete = '${_basePath}delete.png';
  static const String more = '${_basePath}more.png';
  static const String color = '${_basePath}color.png';
  static const String color_point = '${_basePath}color_point.png';
  static const String speed_sub = '${_basePath}speed-.png';
  static const String speed_add = '${_basePath}speed+.png';

  ///读取本地文件
  static Future<Uint8List?> readBinFile(String fileName) async {
    try {
      // 读取 bin 文件
      ByteData data = await rootBundle.load('assets/$fileName');

      // 将 ByteData 转换为 Uint8List 并返回
      return data.buffer.asUint8List();
    } catch (e) {
      print('Error reading bin file: $e');
      return null;
    }
  }
}

List<Map<String, int>> typeList = [
  {'Seven-Color Gradient': 0x25},
  {'Red Gradient': 0x26},
  {'Green Gradient': 0x27},
  {'Blue Gradient': 0x28},
  {'Yellow Gradient': 0x29},
  {'Cyan Gradient': 0x2A},
  {'Purpple Gradient': 0x2B},
  {'White Gradient': 0x2C},
  {'Red-Green Gradient': 0x2D},
  {'Red-Blue Gradient': 0x2E},
  {'Green-Blue Bradient': 0x2F},
  {'Seven-Color Strobe': 0x30},
  {'Red Strobe': 0x31},
  {'Green Strobe': 0x32},
  {'Blue Strobe': 0x33},
  {'Yellow Strobe': 0x34},
  {'Cyan Strobe': 0x35},
  {'Purpple Strobe': 0x36},
  {'White Strobe': 0x37},
  {'Seven Color Jump': 0x38}
];
